<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<#include "/include/head_common.ftl">
	<#include "/include/login_trace.ftl">
	<#assign permissionSet = fm.getPermission() />
	<#assign edit= fm.hasPermission("sql:define:edit",permissionSet)/>
	<#assign view= fm.hasPermission("sql:define:view",permissionSet)/>
	<#assign disabled = edit?string('','disabled')/>
<title>
	<#if edit>
		SQL<#if define.id??>修改<#else>添加</#if>
	<#else>
		SQL查看
	</#if>
</title>
<meta name="decorator" content="default" />
<script type="text/javascript">
	$(document).ready(
			function() {
				closeTip();
				$("#value").focus();
				$("#inputForm")
						.validate(
								{
									submitHandler : function(form) {
										loading('正在提交，请稍等...');
										form.submit();
									},
									errorContainer : "#messageBox",
									errorPlacement : function(error, element) {
										$("#messageBox").text("输入有误，请先更正。");
										if (element.is(":checkbox")
												|| element.is(":radio")
												|| element.parent().is(
														".input-append")) {
											error.appendTo(element.parent()
													.parent());
										} else {
											error.insertAfter(element);
										}
									}
								});
			});
	function goback(){
    	$.cookie('goback','goback',{path: '/',expires: 1});
    	history.go(-1);
    }

</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<#if view >
			<li><a href="${rootUrl}/sql/define/list">SQL列表</a></li>
		</#if>
		<li class="active">
			<a href="${rootUrl}/sql/define/edit?id=${define.id!''}">
				<#if edit>
					SQL<#if define.id??>修改<#else>添加</#if>
				<#else>
					SQL查看
				</#if>
			</a>
		</li>
		<#if fm.hasPermission("sql:parameter:view",permissionSet) >
			<li><a href="${rootUrl}/sql/parameter/list">SQL参数列表</a></li>
		</#if>
		<#if fm.hasPermission("sql:parameter:edit",permissionSet) >
			<li><a href="${rootUrl}/sql/parameter/edit">SQL参数添加</a></li>
		</#if>
		<#if fm.hasPermission("sql:fieldTransform:view",permissionSet) >
			<li><a href="${rootUrl}/sql/fieldTransform/list">列转换器列表</a></li>
		</#if>
		<#if fm.hasPermission("sql:fieldTransform:edit",permissionSet) >
			<li><a href="${rootUrl}/sql/fieldTransform/edit">列转换器添加</a></li>
		</#if>
	</ul>
	<br />
	<form id="inputForm" action="${rootUrl}/sql/define/edit" method="post"
		class="form-horizontal form-signin">
		<input type="hidden" name="id" value="${define.id!''}" />
		<div class="control-group">
			<label class="control-label">定义的key:</label>
			<div class="controls">
				<input id="value" name="defineKey" value="${define.defineKey!''}" maxlength="50"
					class="required"  type="text" <#if !edit || define.id??> disabled </#if> />
			</div>
		</div>

		<div class="control-group">
			<label class="control-label">数据源:</label>
			<div class="controls">
				<select id="dataSource" name="dataSource" class="input-large">
					<option value="">请选择...</option>
					<#list datasourceList as datasource>
						<option value="${datasource.name}"  <#if define.dataSource?? && datasource.name = define.dataSource> selected </#if> >${datasource.name}</option>
					</#list>
				</select>
			</div>
		</div>


		<div class="control-group">
			<label class="control-label">描述:</label>
			<div class="controls">
				<input id="sqlDescribe" name="sqlDescribe" value="${define.sqlDescribe!''}" maxlength="50"
					   class="required"  type="text" ${disabled}/>
			</div>
		</div>

		<div class="control-group">
			<label class="control-label">是否下划线转驼峰:</label>
			<div class="controls">
				<#if define.underLineToCamel??>
					<label><input ${disabled} name="underLineToCamel" type="radio" value="true"<#if define.underLineToCamel>checked="checked"</#if> />是</label>
					<label><input ${disabled} name="underLineToCamel" type="radio" value="false"<#if !define.underLineToCamel>checked="checked"</#if> />否</label>
				<#else>
					<label><input ${disabled} name="underLineToCamel" type="radio" value="true"  checked="checked" />是</label>
					<label><input ${disabled} name="underLineToCamel" type="radio" value="false" />否</label>
				</#if>
			</div>
		</div>

		<div class="control-group">
			<label class="control-label">是否允许页面空参数查询:</label>
			<div class="controls">
				<#if define.allowEmptyParamQuery??>
					<label><input ${disabled} name="allowEmptyParamQuery" type="radio" value="true"<#if define.allowEmptyParamQuery>checked="checked"</#if> />是</label>
					<label><input ${disabled} name="allowEmptyParamQuery" type="radio" value="false"<#if !define.allowEmptyParamQuery>checked="checked"</#if> />否</label>
				<#else>
					<label><input ${disabled} name="allowEmptyParamQuery" type="radio" value="true"  />是</label>
					<label><input ${disabled} name="allowEmptyParamQuery" type="radio" value="false" checked="checked"/>否</label>
				</#if>
			</div>
		</div>

		<div class="control-group">
			<label class="control-label">web页面自动加载查询:</label>
			<div class="controls">
				<#if define.autoWebLoad??>
					<label><input ${disabled} name="autoWebLoad" type="radio" value="true"<#if define.autoWebLoad>checked="checked"</#if> />是</label>
					<label><input ${disabled} name="autoWebLoad" type="radio" value="false"<#if !define.autoWebLoad>checked="checked"</#if> />否</label>
				<#else>
					<label><input ${disabled} name="autoWebLoad" type="radio" value="true"  />是</label>
					<label><input ${disabled} name="autoWebLoad" type="radio" value="false" checked="checked"/>否</label>
				</#if>
			</div>
		</div>

		<div class="control-group">
			<label class="control-label">web页面表格居中显示:</label>
			<div class="controls">
				<#if define.htmlCenterShow??>
					<label><input ${disabled} name="htmlCenterShow" type="radio" value="true"<#if define.htmlCenterShow>checked="checked"</#if> />是</label>
					<label><input ${disabled} name="htmlCenterShow" type="radio" value="false"<#if !define.htmlCenterShow>checked="checked"</#if> />否</label>
				<#else>
					<label><input ${disabled} name="htmlCenterShow" type="radio" value="true"  />是</label>
					<label><input ${disabled} name="htmlCenterShow" type="radio" value="false" checked="checked"/>否</label>
				</#if>
			</div>
		</div>


		<div class="control-group">
			<label class="control-label">列表页隐藏的列:</label>
			<div class="controls">
				<input id="hideColumns" name="hideColumns" value="${define.hideColumns!''}"
					   class="input-xxlarge" style="width: 800px;" type="text" ${disabled}/>
			</div>
		</div>


		<div class="control-group">
			<label class="control-label">查询SQL:</label>
			<div class="controls">
				<textarea name="sqlBase64" rows="10" class="input-xxlarge required" style="height: 200px; width: 800px;" ${disabled}><#if define.id??>${fm.fromBase64(define.sqlBase64!'')}</#if></textarea>
			</div>
		</div>


		<div class="control-group">
			<label class="control-label">参数校验脚本:</label>
			<div class="controls">
				<textarea name="paramVerify" rows="10" class="input-xxlarge" style="height: 200px; width: 800px;" ${disabled}><#if define.paramVerify??>${define.paramVerify!''}</#if></textarea>
			</div>
		</div>

		<div class="control-group">
			<label class="control-label">查询总数的SQL:</label>
			<div class="controls">
				<textarea name="countSqlBase64" rows="10" class="input-xxlarge" style="height: 200px; width: 800px;" ${disabled}><#if define.id?? && define.countSqlBase64 ?? && (define.countSqlBase64?trim?length > 0)>${fm.fromBase64(define.countSqlBase64!'')}</#if></textarea>
			</div>
		</div>
		<input type="hidden" name="version" value="${define.version!''}"/>
		<div class="form-actions">
			<#if edit>
			<input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存" />&nbsp;
			</#if>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="goback()" />
		</div>
	</form>
</body>
</html>